#ifndef __MERCATOR_H__
#define __MERCATOR_H__

using namespace std;
namespace ns_yht
{
	class Mercator
	{
	private:
		static double mercatorMinX;
		static double mercatorMinY;
		static double mercatorMaxX;
		static double mercatorMaxY;

	public:
		static double PI;

	public:
		Mercator();
		~Mercator();

		/// <summary>
		/// 根据给定的经纬度转换为投影实例
		/// </summary>
		/// <param name="location">经纬度</param>
		/// <returns>投影值</returns>
		static double ToX(double lon);
		static double ToY(double lat);
		/// <summary>
		/// 根据给定的投影值转换为经纬度
		/// </summary>
		/// <param name="location">投影值</param>
		/// <returns>经纬度</returns>
		static double ToLon(double x);
		static double ToLat(double y);

		/**
		 * @brief 计算两个经纬度之间的方位角
		 *
		 * @return double [0-360)
		 */
		static double calculateBearing(double lat1, double lon1, double lat2, double lon2);

		/**
		 * @brief 计算两个投影值之间的方位角
		 *
		 * @param x1
		 * @param y1
		 * @param x2
		 * @param y2
		 * @return double [0-360)
		 */
		static double calculateBearingXY(double x1, double y1, double x2, double y2);

		/**
		 * @brief 计算两个经纬度之间的距离
		 *
		 * @return double 米
		 */
		static double calculateDistance(double lat1, double lon1, double lat2, double lon2);
		/**
		 * @brief 计算两个投影值之间的距离
		 *
		 * @return double 米
		 */
		static double calculateDistanceXY(double x1, double y1, double x2, double y2);

		/**
		 * @brief 计算两个经纬度之间的距离和方位角
		 *
		 * @param distance 米
		 * @param bearing [0-360)
		 */
		static void calculateDistanceAndBearing(double lat1, double lon1, double lat2, double lon2, double &distance, double &bearing);

		/**
		 * @brief 计算两个投影值之间的距离和方位角
		 *
		 * @param distance 米
		 * @param bearing [0-360)
		 */
		static void calculateDistanceAndBearingXY(double x1, double y1, double x2, double y2, double &distance, double &bearing);

		/**
		 * @brief 计算经度的中心，简单相加求平均是有误差的
		 */
		static double centerLon(double lon1, double lon2);

		/**
		 * @brief 计算纬度的中心，简单相加求平均是有误差的
		 */
		static double centerLat(double lat1, double lat2);
	};
}
#endif
